package com.system.demo.controller.leave;


import cn.dev33.satoken.annotation.SaCheckPermission;
import com.system.demo.entity.DTO.LeaveRequestDTO;
import com.system.demo.entity.DTO.SubmitApplicationInfo;
import com.system.demo.service.LeaveService;
import com.system.demo.tool.ResponseResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/leave/student")
public class LeaveController {

    @Autowired
    private LeaveService leaveService;

    /**
     * 学生上传离校申请
     *
     * @param leaveRequestDTO      前端提交的离校申请表单
     * @return    返回信息
     */
    @PostMapping("/apply")
    @SaCheckPermission("AbsenceApply")
    public ResponseResult<?> leavingSubmitApplication(@ModelAttribute LeaveRequestDTO leaveRequestDTO) {
        if (leaveRequestDTO.getPicture() == null || leaveRequestDTO.getPicture().isEmpty()) {
            return ResponseResult.NotFound("上传的文件不能为空");
        }
        return leaveService.leavingSubmitApplication(leaveRequestDTO);
    }

    /**
     * 学生查看离校申请
     *
     * @param current      目前页面
     * @param size         一页面有几条申请
     * @return    返回信息
     */

    @PostMapping("/view")
    @SaCheckPermission("AbsenceApply")
    public ResponseResult<?> leavingView(@RequestParam int current, int size ){
        return leaveService.leavingView(current,size);
    }


    /**
     *学生撤销个人申请
     * @param applicationId    数据库id
     * @return
     */
    @PostMapping("/delete")
    @SaCheckPermission("AbsenceApply")
    public ResponseResult<?> LeaveApplicationDelete(@RequestParam Integer applicationId) {
        return leaveService.leaveDelete(applicationId);
    }


    /**
     *学生修改个人申请
     * @param applicationId    数据库id
     * @param leaveRequestDTO  提交的申请表单
     * @return
     */
    @PostMapping("/update")
    @SaCheckPermission("AbsenceApply")
    public ResponseResult<?> LeaveApplicationUpdate(@RequestParam Integer applicationId,@ModelAttribute LeaveRequestDTO leaveRequestDTO) {
        if (leaveRequestDTO.getPicture() == null || leaveRequestDTO.getPicture().isEmpty()) {
            return ResponseResult.NotFound("上传的文件不能为空");
        }
        return leaveService.leaveApplicationUpdate(applicationId,leaveRequestDTO);
    }


    /**
     * 学生返校销假：
     *
     * @param applicationId 数据库id
     * @return 返回信息
     */

    @PostMapping("/back")
    @SaCheckPermission("AbsenceApply")
    public ResponseResult<?> LeaveApplicationBack(@RequestParam Integer applicationId) {
        return leaveService.leaveApplicationBack(applicationId);
    }



}
